package org.jdpf.gui.rcp.neteditor.core.elements;

import org.jdpf.core.kernel.exceptions.CoreException;
import org.jdpf.core.kernel.exceptions.CoreExceptionsEnum;
import org.jdpf.core.kernel.exceptions.ErrorConverterException;
import org.jdpf.core.kernel.exceptions.IllegalParametersException;

public class GraphicNetAsTaskValidationStatus {
	
	public final static int VALID = 0;

	public final static int WARNING = 1;

	public final static int ERROR = 2;

	private String statusMessage;

	private int type;

	private String transitionIdWithErrors;
	
	private String paramNameWithErrors;

	private CoreException e;

	private boolean netValidation;


	public GraphicNetAsTaskValidationStatus(String status, int type) {
		this.statusMessage = status;
		this.type = type;
	}
	
	public GraphicNetAsTaskValidationStatus(CoreException e){
		this.e = e;
		this.statusMessage = e.getErrorMessage();
		this.type = ERROR;
		
		if(e.getExceptionCode().equals(CoreExceptionsEnum.IllegalParameters)){
			transitionIdWithErrors = ((IllegalParametersException)e).getTransitionIdWithErrors();
			paramNameWithErrors = ((IllegalParametersException)e).getParameterNameWithErrors();;
		} else if(e.getExceptionCode().equals(CoreExceptionsEnum.ErrorConverter)){
			transitionIdWithErrors = ((ErrorConverterException)e).getTransitionIdWithErrors();
			paramNameWithErrors = null;
		}
	}
	
	public String getTransitionIdWithErrors(){
		return transitionIdWithErrors;
	}

	public String getParameterNameWithErrors(){
		return paramNameWithErrors;
	}
	
	public String getStatusMessage() {
		return statusMessage;
	}

	public int getType() {
		return type;
	}
	
	public CoreExceptionsEnum getExceptionCode(){
		if(e!=null)
			return e.getExceptionCode();
		else
			return CoreExceptionsEnum.Unknown;
	}

	/**
	 * This method returns the validation flag related only to the Net
	 * @return The specific Net validation flag
	 */
	public boolean isNetValid(){
		return netValidation;
	}
	
	public void setNetValidation(boolean isValid){
		this.netValidation = isValid;
	}
}